package com.example.parking.consumer;/*
 * @author 陈政
 * @date 2020-08-26 15:14
 */

import com.alibaba.fastjson.JSONObject;
import com.example.parking.service.ParkingEsService;
import com.example.parking.service.ParkingService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pojo.Parking;
import vo.HomeParkingVo;

@Component
public class ParkingConsumer {
    
    @Autowired
    ParkingEsService parkingEsService;
    @Autowired
    ParkingService parkingService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "create",durable = "true"),
            exchange = @Exchange(
                    value = "airparking_parking",
                    ignoreDeclarationExceptions = "true"
            ),
            key = {"parking.create"}
    ))
    public void routingConsumer1(String msg){
        Parking parking = JSONObject.parseObject(msg, Parking.class);
        System.out.println("rabbitmq收到消息，存入es"+ parking);
        HomeParkingVo homeParkingVo = parkingService.selectByPrimaryKey(parking.getParkingId());
        parkingEsService.save(homeParkingVo);
    }
}
